#include <dbg/ptest.h>
#include <stdlib.h>
#include <compl.h>
#include <dbg.h>
#include <time.h>
void test_simple(){
	fprintf(stderr, "simple test ready\n");
	void *mem = malloc(sizeof(unsigned long));\
	fprintf(stderr, "simple test alloc %p\n", mem);
	__memset(mem, 0, sizeof(unsigned long));
	free(mem);
	cmb();
	fprintf(stderr, "simple test ok\n");
}

static const size_t blk_nr = 1024;
static const size_t blk_maxsize = 65536;
static const size_t blk_test_nr = 65536;

void test_simple_rand(){
	void *mem[blk_test_nr];
	size_t size;
	size_t seed = rdcnt_relax();
	struct timespec ts, td;
	TIME_STAMP(&ts);
	for (size_t idx = 0; idx < blk_test_nr; idx++){
		mem[idx] = malloc(hash(seed + idx) % blk_maxsize);
	}
	TIME_STAMP(&td);
	fprintf(stderr, "[m%lu] %llums, randsz_max %lu\n", blk_test_nr, TIME_DELTA_MS(&ts, &td), blk_maxsize);
	
	TIME_STAMP(&ts);
	for (size_t idx = 0; idx < blk_test_nr; idx++){
		// fprintf(stderr, "[f]%p\n", mem[idx]);
		free(mem[idx]);
	}
	TIME_STAMP(&td);
	fprintf(stderr, "[f%lu] %llums, randsz_max %lu\n", blk_test_nr, TIME_DELTA_MS(&ts, &td), blk_maxsize);
}

int main(){
	fprintf(stderr, "main ready\n");
	test_simple();
	test_simple_rand();
}